<?php
/**
 * Created by PhpStorm.
 * User: KaZeline
 * Date: 15-11-11
 * Time: 上午10:16
 */


//把本服务器上的journal表里的数据搬到 10.117.7.197 里面
$jc = file_get_contents('../mark.txt');
//echo $jc;
if($jc=='journal1.3')
    exit('重复操作');
file_put_contents('../mark.txt','journal1.3');
use \PFT\Db;
include_once '/var/www/html/new/d/module/common/Db.class.php';
$dbConf = include_once '/var/www/html/new/d/module/common/db.conf.php';// 远端服务器配置信息.

Db::Conf($dbConf['localhost']);
$con_0 = Db::connect('0');
Db::Close('0');

Db::Conf($dbConf['remote_2']);
$con_1 = Db::connect('1');
Db::Close('1');

$max = 6300000;//下一次 $i=6300
$sql_base = "insert into pft_member_journal (fid,dmoney,lmoney,aid,orderid,daction,rectime,opid,dtype,ptype,memo) values ";
for($i=100;$i<ceil($max/1000);$i++){
    $value = '';
    $up_limit  = ($i+1)*1000;
    $low_limit = ($i)*1000;
    $sql_0 = "select fid,dmoney,lmoney,aid,orderid,daction,rectime,opid,dtype,ptype,memo from pft_member_journal where id<$up_limit and id>=$low_limit";
    $stmt = $con_0->prepare($sql_0);
    $stmt->execute();
    while($row = $stmt->fetch(\PDO::FETCH_ASSOC)){
        $value .= "({$row['fid']},{$row['dmoney']},{$row['lmoney']},{$row['aid']},'{$row['orderid']}',{$row['daction']},'{$row['rectime']}',{$row['opid']},{$row['dtype']},{$row['ptype']},'{$row['memo']}')".',';
//        break;
    }
    $value = rtrim($value,',');
    $sql_1 = $sql_base.$value;
//    echo $sql_1;

    $stmt = $con_1->prepare($sql_1);
    if($insert_return = $stmt->execute()){
        echo '插入成功','<br/>';
        ob_flush();
        flush();
    }else{
        echo '<pre>';
        print_r($stmt->errorInfo());
        echo '</pre>';
        echo '$i:',$i;
        echo $sql_1;
        exit;
    }
//    break;
}
$con_1 = $con_0 = null;